<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>

    <link rel="stylesheet" type="text/css" href="/static/lib/datatables/1.10.15/jquery.dataTables.css">
    <div th:include="admin/common :: head"></div>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/static/lib/html5shiv.js"></script>
    <script type="text/javascript" src="/static/lib/respond.min.js"></script>
    <![endif]-->

    <script type="text/javascript">
        $(function(){
            init_city_select($("#district"));
        });
    </script>
    <title>添加题目</title>
</head>

<body>

<article class="page-container">
    <form action="/admin/question/questionAdd" class="form form-horizontal"
          id="form-teacher-add" method="POST">

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">题目类型：</label>
            <div class="formControls col-xs-8 col-sm-9">
				<span class="select-box">
					<select name="questionType" class="select">
						<option value="1">单项选择</option>
						<option value="2">不定项选择</option>
						<option value="3">填空题</option>
						<option value="4">简答题</option>
					</select>
				</span>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">问题类型：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <select name="type" >
                    <option name="type" th:each="course,courseType:${courseTypeList}"
                            th:value="${course.courseType}" th:text="${course.name}"></option>
                </select>
            </div>
        </div>


        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">描述：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea name="questionDesc" cols="" rows="" class="textarea"  placeholder="问题描述"
                          onKeyUp="$.Huitextarealength(this,100)"></textarea>
                <p class="textarea-numberbar"><em class="textarea-length"></p>
            </div>
        </div>

        <div class="row cl choose">
            <label class="form-label col-xs-4 col-sm-2">选项：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea name="choice" cols="" rows="" class="textarea"
                          placeholder="如:A.xxxx-B.xxxx-C.xxxx-D.xxxx"
                          onKeyUp="$.Huitextarealength(this,100)"></textarea>
                <p class="textarea-numberbar"><em class="textarea-length"></p>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">答案：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea name="answer" cols="" rows="" class="textarea"  placeholder="答案"
                          onKeyUp="$.Huitextarealength(this,100)"></textarea>
                <p class="textarea-numberbar"><em class="textarea-length"></p>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">分数：</label>
            <div class="formControls col-xs-8 col-sm-9">
				<span class="">
					<select name="questionGrade" class="">
						<option value="1">1</option>
						<option value="2">2</option>
						<option value="3">3</option>
						<option value="4">4</option>
                        <option value="5">5</option>
						<option value="6">6</option>
						<option value="7">7</option>
						<option value="8">8</option>
                        <option value="9">9</option>
						<option value="10">10</option>
					</select>
				</span>
            </div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

<footer th:include="admin/common :: footer"></footer>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="/static/lib/datatables/1.10.15/jquery.dataTables.js"></script>
<script type="text/javascript" src="/static/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="/static/lib/webuploader/0.1.5/webuploader.min.js"></script>



<script type="text/javascript">
    $(function(){

        $('.select').change(function(){
            if($(this).val()==3||$(this).val()==4){
                $('.choose').css('display','none');
            }else{
                $('.choose').css('display','block');
            }
        })
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        $("#form-teacher-add").validate({
            rules:{
                questionDesc:{
                    required:true,
                },

            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                //这里使用异步提交是为了验证区域存不存在
                //form.submit();

                /* alert(5456);
                $(form).ajaxSubmit({

                    url : "${pageContext.request.contextPath}/teacher/teacherAdd",
                    type : "POST",
                    data : fd,
                    dataType : "json",
                    processData : false, // 告诉jQuery不要去处理发送的数据
                    contentType : false, // 告诉jQuery不要去设置Content-Type请求头
                    success: function(data){
                        if (data.status==1){
                            alert("添加教师成功");
                            location.href="${pageContext.request.contextPath}/teacher/teacherList";
                        }else{
                            alert("添加失败！");
                        }
                    }
                }); */

                /*var index = parent.layer.getFrameIndex(window.name);
                //parent.$('.btn-refresh').click();
                parent.layer.close(index); */

                var fd = new FormData($("#form-teacher-add")[0]);
                $.ajax({
                    url : "/admin/question/questionAdd",
                    type : "post",
                    data : fd,
                    dataType : "json",
                    processData : false, // 告诉jQuery不要去处理发送的数据
                    contentType : false, // 告诉jQuery不要去设置Content-Type请求头
                    success: function(data){
                        if (data.code === 200){
                            alert("添加成功");
                            /*location.href="/user/createCourse/course";*/
                        }else{
                            alert("修改失败！");
                        }
                    }
                });
            }
        });
    });
</script>
</body>
</html>